﻿using msBsc.AppLogic.DataAlc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Buyer
{
    public partial class wfMessage : msBsc.Cls.BPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void GetAllMessage()
        {
            int pageIndex = 1;
            int.TryParse(this.GetParamHtValue("pIndex"), out pageIndex);
            int pageSize = 10;
            string solderid = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(solderid))
            {
                this.ExecJScript(@"layer.alert('登录失效请重新登录.', 3);");
                return;
            }

            using (CBizMessageSystem msg = new CBizMessageSystem())
            {

                DataTable dt = msg.GetMsgList(solderid,3, pageSize, pageIndex);
                if (dt == null || dt.Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_msg').html();
                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#messageList').html(render);
                            });jsPage('divPage', " + dt.Rows[0]["DATACOUNT"] + ", " + pageSize + ", " + pageIndex + ", 'goPage');");
            }

        }
        public void UpdateStatus()
        {
            string msgid = this.GetParamHtValue("msgid");

            string solderid = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(solderid))
            {
                return;
            }
            using (CBizMessageSystem Message = new CBizMessageSystem())
            {
                string msg = Message.UpdateStatus(msgid);
                if (msg!="OK")
                {
                    return;
                }

                this.ExecJScript("$('#"+msgid+"').attr('status','1');");
            }

        }


        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                //初始化
                GetAllMessage();
            }
            else if (this.strAction == "up")
            {
                UpdateStatus();
            }
        }
    }
}